<#include "/admin/inc/page.html">
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计划 - UnaBoot</title>
    <link rel="icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/font-awesome.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/ionicons.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/adminlte.css">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/layer/skin/default/layer.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/unaboot-admin.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700">
</head>
<body class="sidebar-mini layout-fixed layout-navbar-fixed text-md <!--sidebar-collapse-->">
    <div class="wrapper">
        <nav class="main-header navbar navbar-expand navbar-white navbar-light">
            <#include "/admin/inc/header.html">
        </nav>
        <aside class="main-sidebar sidebar-dark-primary ">
            <#include "/admin/inc/aside.html">
        </aside>
        <div class="content-wrapper bg-gray-custom">
            <div class="content-header pb-0">
                <div class="row mb-2">
                    <div class="col-12">
                        <h4 class="ml-2 mb-0 text-dark">计划
                            <button id="new-schedule" class="btn btn-sm btn-outline-primary">新增计划</button>
                        </h4>
                    </div>
                </div>
            </div>
            <div class="content">
                <div class="container-fluid">
                    <!--数据列表-->
                    <div class="row text-sm mt-1">
                        <div class="col-12">
                            <table class="table post-datatable table-striped table-hover" style="border: 1px solid #ddd">
                                <thead>
                                    <tr class="bg-white">
                                        <td width="30%">类型</td><td>描述</td><td>Cron</td><td>Params</td><td>状态</td><td>创建者</td><td>日期</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <#if data?? && data.content?size gt 0>
                                        <#list data.content as schedule>
                                            <tr>
                                                <td>
                                                    <#list methods as method>
                                                        <#if method.getName() == schedule.method>
                                                            ${method.getAlias()}
                                                        </#if>
                                                    </#list>
                                                    <div class="row-actions">
                                                        <#if schedule.state == true>
                                                            <span class="forbidden">
                                                                <a href="javascript:void(0);" aria-id="${schedule.id}" class="text-secondary"><i class="fa fa-frown-o"></i>停止</a> <small class="text-secondary"> |</small>
                                                            </span>
                                                        <#else>
                                                            <span class="open">
                                                                <a href="javascript:void(0);" aria-id="${schedule.id}" class="text-green"><i class="fa fa-smile-o"></i>启用</a>
                                                            </span>
                                                            <span class="edit">
                                                                <a href="javascript:void(0);" aria-id="${schedule.id}"><i class="fa fa-edit"></i>编辑</a> <small class="text-secondary"> |</small>
                                                            </span>
                                                        </#if>
                                                        <span class="trash">
                                                            <a href="javascript:void(0);" aria-id="${schedule.id}"><i class="fa fa-trash-o"></i>移除</a>
                                                        </span>
                                                    </div>
                                                </td>
                                                <td>
                                                    <textarea rows="1" readonly style="background: #fff;resize: none" class="form-control form-control-sm">${schedule.introduce!'Unintroduce'}</textarea>
                                                </td>
                                                <td>
                                                    <input type="text" readonly class="input-sm form-control form-control-sm" style="height: 28px;background: #fff;" value="${schedule.cronExp!'UnCronExp'}">
                                                <td>
                                                    ${schedule.params!'UnParameters'}
                                                </td>
                                                <td>
                                                    <#if schedule.state == true>
                                                        <i class="fa fa-spin fa-refresh text-green"></i>
                                                    <#else>
                                                        <i class="fa fa-stop text-secondary"></i>
                                                    </#if>
                                                </td>
                                                <td>${schedule.creator!'System'}</td>
                                                <td>
                                                    更新于<br>
                                                    <span class="post-time"><i class="fa fa-calendar-o"></i> ${schedule.updateTime?string("yyyy-MM-dd HH:mm:ss")}</span>
                                                </td>
                                            </tr>
                                        </#list>
                                    <#else>
                                        <tr><td colspan="7" class="text-center text-secondary">暂无可用数据!</td></tr>
                                    </#if>
                                </tbody>
                                <tfoot>
                                    <tr class="bg-white">
                                        <td width="30%">类型</td><td>描述</td><td>Cron</td><td>Params</td><td>状态</td><td>创建者</td><td>日期</td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                    <!--分页按钮-->
                    <div class="row text-sm mt-1">
                        <#if data?? && data.content?size gt 0 && data.totalPages gt 1>
                            <div class="col-12">
                                <nav aria-label="..." class="pull-right">
                                    <@pagination una+"/admin/schedules/" data 9/>
                                </nav>
                            </div>
                        </#if>
                    </div>
                </div>
            </div>
        </div>
        <footer class="main-footer">
            <#include "/admin/inc/footer.html">
        </footer>
    </div>
    <script src="${una}/ub-admin/plugin/jquery/jquery.min.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/plugin/bootstrap/js/bootstrap.bundle.min.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/js/adminlte.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/plugin/layer/layer.js"></script>
    <script src="${una}/ub-admin/js/unaboot-admin.core.js" type="text/javascript"></script>
    <script type="text/javascript">
        $("#new-schedule").on("click",function(){
            layer.open({
                type:2,
                title:"<i class=\"fa fa-plus-circle\"></i> 新增计划",
                shadeClose:false,
                shade:0.4,
                offset:['55px'],
                area:['550px','400px'],
                content:'${una}/admin/schedules/create',
                resize:false,
                anim:1
            })
        });

        $(".forbidden a").on("click",function(){
            var id = $(this).attr("aria-id");
            if(id == null || typeof(id) == 'undefined' ){
                return false;
            }else{
                layer.alert("确定停止该计划吗?",{
                    title:"<i class='fa fa-info-circle'></i> 提示",
                    icon:0,
                    btn:['是(Y)','否(N)'],
                    shadeClose: false,
                    shade:[0.4,'#fff'],
                    anim: 1
                },function(){
                    var load = layer.load(2,{shade:[0.4,'#f0f0f0']});
                    $.ajax({
                        type:'PUT',
                        url:"${una}/admin/schedules/"+id+"/stop",
                        success:function(){
                            layer.close(load);
                            layer.alert("当前操作已成功执行!",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['OK'],
                                yes:function(index){
                                    layer.close(index);
                                    window.location.reload();
                                }
                            });
                        },
                        error:function(){
                            layer.close(load);
                            layer.alert("当前操作失败!请稍后再试。",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['Close'],
                                yes:function(newIndex){
                                    layer.close(newIndex);
                                }
                            });
                        }
                    });
                },function(index){
                    layer.close(index);
                });
            }
        });
        $(".open a").on("click",function(){
            var id = $(this).attr("aria-id");
            if(id == null || typeof(id) == 'undefined' ){
                return false;
            }else{
                layer.alert("确定重启该计划吗?",{
                    title:"<i class='fa fa-info-circle'></i> 提示",
                    icon:0,
                    btn:['是(Y)','否(N)'],
                    shadeClose: false,
                    shade:[0.4,'#fff'],
                    anim: 1
                },function(){
                    var load = layer.load(2,{shade:[0.4,'#f0f0f0']});
                    $.ajax({
                        type:'PUT',
                        url:"${una}/admin/schedules/"+id+"/start",
                        success:function(){
                            layer.close(load);
                            layer.alert("当前操作已成功执行!",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['OK'],
                                yes:function(index){
                                    layer.close(index);
                                    window.location.reload();
                                }
                            });
                        },
                        error:function(){
                            layer.close(load);
                            layer.alert("当前操作失败!请稍后再试。",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['Close'],
                                yes:function(newIndex){
                                    layer.close(newIndex);
                                }
                            });
                        }
                    });
                },function(index){
                    layer.close(index);
                });
            }
        });
        $(".edit a").on("click",function(){
            var id = $(this).attr("aria-id");
            if(id == null || typeof(id) == 'undefined' ){
                return false;
            }else{
                layer.open({
                    type:2,
                    title:"<i class=\"fa fa-edit\"></i> 修改计划",
                    shadeClose:false,
                    shade:0.4,
                    offset:['55px'],
                    area:['550px','400px'],
                    content:"${una}/admin/schedules/"+id,
                    resize:false,
                    anim:1
                });
            }
        });
        $(".trash a").on("click",function(){
            var id = $(this).attr("aria-id");
            if(id == null || typeof(id) == 'undefined' ){
                return false;
            }else{
                layer.alert("确定删除该计划吗?",{
                    title:"<i class='fa fa-info-circle'></i> 提示",
                    icon:0,
                    btn:['是(Y)','否(N)'],
                    shadeClose: false,
                    shade:[0.4,'#fff'],
                    anim: 1
                },function(){
                    var load = layer.load(2,{shade:[0.4,'#f0f0f0']});
                    $.ajax({
                        type:'DELETE',
                        url:"${una}/admin/schedules/"+id,
                        success:function(){
                            layer.close(load);
                            layer.alert("当前操作已成功执行!",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['OK'],
                                yes:function(index){
                                    layer.close(index);
                                    window.location.reload();
                                }
                            });
                        },
                        error:function(){
                            layer.close(load);
                            layer.alert("当前操作失败!请稍后再试。",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['Close'],
                                yes:function(newIndex){
                                    layer.close(newIndex);
                                }
                            });
                        }
                    });
                },function(index){
                    layer.close(index);
                });
            }
        });
    </script>
</body>
</html>